import { createParamDecorator, ExecutionContext, SetMetadata } from "@nestjs/common";

export const  RequireLogin = () => SetMetadata('require-login', true);

export const UserInfo = createParamDecorator(
    (data: string, ctx: ExecutionContext) => {
      const request:any = ctx.switchToHttp().getRequest<Request>();
  
      if(!request.user) {
          return null;
      }
      return data ? request.user[data] : request.user;
    },
  )